package com.turtle3d;

import java.awt.Dimension;
import java.awt.GraphicsEnvironment;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;

import com.turtle3d.gui.Turtle3DLayoutPanel;
import com.turtle3d.gui.console.ConsolePanel;
import com.turtle3d.gui.drawingpanel.DrawingPanel;
import com.turtle3d.gui.fractaloptions.FractalOptionsPanel;
import com.turtle3d.gui.visualoptions.VisualOptionsPanel;

/**
 * Application launcher.
 * 
 * @author Marek Paterczyk <marek.paterczyk@gmail.com>
 * 
 */
public class Turtle3DLauncher
{	

	public static void init(){	
		
		Border panelBorder = BorderFactory.createBevelBorder(BevelBorder.RAISED);
		
		DrawingPanel drawingPanel = new DrawingPanel();
		//printCanvas3D.setVisible(true);
		//printCanvas3D.setBorder(panelBorder);
		
		FractalOptionsPanel fractalOptionsPanel = new FractalOptionsPanel();
		fractalOptionsPanel.setBorder(panelBorder);
				
		VisualOptionsPanel visualOptionsPanel = new VisualOptionsPanel();
		visualOptionsPanel.setPropertyChangeListener(drawingPanel);
		visualOptionsPanel.setBorder(panelBorder);
		
		ConsolePanel consolePanel = new ConsolePanel();
		App.setConsole(consolePanel);
		consolePanel.setBorder(panelBorder);		
		
		FractalGenerator fractalGenerator = new FractalGenerator();
		fractalOptionsPanel.setGenerateFractalListener(fractalGenerator);
		fractalGenerator.setDrawingPanel(drawingPanel);				
				
		JPanel rightPanel = new JPanel();
		rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS));
		rightPanel.add(fractalOptionsPanel);
		rightPanel.add(visualOptionsPanel);
		
		Turtle3DLayoutPanel turtle3DLayoutPanel = new Turtle3DLayoutPanel();
		turtle3DLayoutPanel.setDrawingPanel(drawingPanel);
		turtle3DLayoutPanel.setToolbarPanel(rightPanel);
		turtle3DLayoutPanel.setConsolePanel(consolePanel);
		turtle3DLayoutPanel.initGUI();		
		
		//JFrames:
		JFrame turtle3DJFrame = new JFrame("Turtle3D");
		turtle3DJFrame.setPreferredSize(new Dimension(800,600));
		turtle3DLayoutPanel.setSize(new Dimension(800,600));
		turtle3DLayoutPanel.setSize(new Dimension(800,600));
		turtle3DJFrame.pack();
		{
			GraphicsEnvironment env =
			     GraphicsEnvironment.getLocalGraphicsEnvironment();
			   /*
			     The next line determines if the   taskbar (win) is covered
			     if unremarked, the task will not be covered by
			     the maximized JFRAME.
			   */
			   // this.setMaximizedBounds(env.getMaximumWindowBounds());
			turtle3DJFrame.setExtendedState(turtle3DJFrame.getExtendedState() | turtle3DJFrame.MAXIMIZED_BOTH);
		}
		turtle3DJFrame.getContentPane().add(turtle3DLayoutPanel);					
		turtle3DJFrame.setJMenuBar(drawingPanel.createMenu());
		turtle3DJFrame.setVisible(true);
		turtle3DJFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				
	}
	
	public static void main(String[] args)
	{
		SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.
                                             getSystemLookAndFeelClassName());
                } catch (Exception exception) {
                    exception.printStackTrace();
                }

                init();
            }
        });
		
						
	}

}
